package com.ruoyi.web.controller.business;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WcPatentApplication;
import com.ruoyi.system.domain.WcPatentApplicationAncillary;
import com.ruoyi.system.domain.WcPatentApplicationCompany;
import com.ruoyi.system.domain.vo.business.*;
import com.ruoyi.system.dto.handleRecord.IdSearchVO;
import com.ruoyi.system.service.IWcPatentApplicationAncillaryService;
import com.ruoyi.system.service.IWcPatentApplicationCompanyService;
import com.ruoyi.system.service.IWcPatentApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 剧本备案申请Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Controller
@Api(tags = {"剧本备案申请"})
@RequestMapping("/system/wcPatentApplication")
public class WcPatentApplicationController extends BaseController {

    @Autowired
    private IWcPatentApplicationService service;

    @Autowired
    private IWcPatentApplicationAncillaryService ancillaryService;

    /**
     * 查询剧本备案申请列表
     */
    @ApiOperation("查询剧本备案申请列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> list(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.list(dto);
        return AjaxResult.success(list);
    }

    // todo 剧本备案开始
    /**
     * 电影剧本备案--查询剧本备案受理列表
     */
    @ApiOperation("电影剧本备案--查询剧本备案【受理】列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/acceptanceList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> acceptanceList(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.acceptanceList(dto);
        return AjaxResult.success(list);
    }

    /**
     * 电影剧本备案--查询剧本备案专家评审列表
     */
    @ApiOperation("电影剧本备案--查询剧本备案【专家评审】列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/expertReviewList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> expertReviewList(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.expertReviewList(dto);
        return AjaxResult.success(list);
    }

    /**
     * 电影剧本备案--查询剧本备案公示发证列表
     */
    @ApiOperation("电影剧本备案--查询剧本备案【公示发证】列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/publicizeCertificationList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> publicizeCertificationList(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.publicizeCertificationList(dto);
        return AjaxResult.success(list);
    }

    /**
     * 电影剧本备案--查询剧本备案审查决定列表
     */
    @ApiOperation("电影剧本备案--查询剧本备案【审查决定】列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/reviewDecisionList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> reviewDecisionList(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.reviewDecisionList(dto);
        return AjaxResult.success(list);
    }

    /**
     * 电影剧本备案--查询剧本备案公示信息列表
     */
    @ApiOperation("电影剧本备案--查询剧本备案【公示信息】列表")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @PostMapping("/publicityInfoList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationPublicityInfoListVo>> publicityInfoList(@RequestBody WcPatentApplicationPublicityInfoListDto dto) {
        Page<WcPatentApplicationPublicityInfoListVo> list = service.publicityInfoList(dto);
        return AjaxResult.success(list);
    }



// todo 剧本备案结束

    /**
     * 导出剧本备案申请列表
     */
    @ApiOperation("导出剧本备案申请列表")
    //@RequiresPermissions("system:application:export")
    @Log(title = "剧本备案申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody WcPatentApplicationSelectListDto dto) {
        Page<WcPatentApplicationSelectListVO> list = service.list(dto);
        ExcelUtil<WcPatentApplicationSelectListVO> util = new ExcelUtil<>(WcPatentApplicationSelectListVO.class);
        return util.exportExcel(list.getRecords(), "剧本备案申请数据");
    }

    /**
     * 新增保存剧本备案申请
     */
    @ApiOperation("(app)新增剧本备案申请")
    //@RequiresPermissions("system:application:add")
    @Log(title = "(app)剧本备案申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult<String> addSave(@RequestBody WcPatentApplicationSaveVO saveVO) throws Exception {
        return success(service.addSave(saveVO));
    }

    /**
     * 剧本备案申请详情
     */
    @ApiOperation("剧本备案申请详情")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:detail')")
    @GetMapping("/selectById/{id}")
    @ResponseBody
    public AjaxResult<WcPatentApplicationDetailVO> edit(@PathVariable("id") Long id) {
        WcPatentApplicationDetailVO vo = service.selectWcPatentApplicationDetailVOById(id);
        return success(vo);
    }

    /**
     * 修改保存剧本备案申请
     */
    @ApiOperation("修改剧本备案申请")
    //@RequiresPermissions("system:application:edit")
    @Log(title = "剧本备案申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult<String> editSave(@RequestBody WcPatentApplicationUpdateVO wcPatentApplication) throws Exception {
        return success(service.updateSave(wcPatentApplication));
    }

    /**
     * 删除剧本备案申请
     */
    @ApiOperation("删除剧本备案申请")
    //@RequiresPermissions("system:application:remove")
    @Log(title = "剧本备案申请", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id) {
        boolean b = service.removeById(id);
        //附件一块删除
        ancillaryService.remove(Wrappers.lambdaQuery(WcPatentApplicationAncillary.class).
                eq(WcPatentApplicationAncillary::getWcPatentApplicationId,id));
        return toAjax(b);
    }



    /**
     * 新增保存剧本备案申请
     */
    @ApiOperation("【新】新增反馈国家电影局信息")
    @Log(title = "【新】新增反馈国家电影局信息", businessType = BusinessType.INSERT)
    @PostMapping("/add_recommendation")
    @ResponseBody
    public AjaxResult<String> addRecommendation(@RequestBody WcPatentApplicationRecommendationVO saveVO) throws Exception {
        return success(service.addRecommendation(saveVO));
    }


    /**
     * 新增保存剧本备案申请
     */
    @ApiOperation("【新】查询反馈国家电影局信息")
    @PreAuthorize("@ss.hasPermi('system:patentApplication:list')")
    @Log(title = "【新】新增反馈国家电影局信息", businessType = BusinessType.OTHER)
    @GetMapping("/get_recommendation")
    public AjaxResult<List<WcPatentApplicationRecommendationVO>> getList( @ApiParam(value = "查询参数") @ModelAttribute IdSearchVO saveVO) throws Exception {
        return AjaxResult.success(service.getRecommendationList(saveVO));
    }


}
